package com.ics.webapp.action;

import com.ics.model.CommodityTeam;
import com.ics.service.CommodityTeamManager;
import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 11-10-31
 * Time: 下午6:20
 * To change this template use File | Settings | File Templates.
 */
public class CommodityTeamAction extends BaseAction{
    private CommodityTeamManager commodityTeamManager;
    private List commodityTeams;
    private CommodityTeam commodityTeam;
    private Long id;
    public  void setCommodityTeamManager(CommodityTeamManager commodityTeamManager){
        this.commodityTeamManager=commodityTeamManager;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List getCommodityTeams(){
        return commodityTeams;
    }
    public String list(){
        commodityTeams=commodityTeamManager.getCommodityTeams();
        return SUCCESS;
    }

    public CommodityTeam getCommodityTeam() {
        return commodityTeam;
    }
    public void setCommodityTeam(CommodityTeam commodityTeam){
        this.commodityTeam=commodityTeam;
    }
    public String delete(){
        commodityTeamManager.remove(commodityTeam.getId());
        saveMessage(getText("commodityTeam.deleted"));
        return SUCCESS;
    }
    public String edit(){
        if(id!=null){
            commodityTeam=commodityTeamManager.getCommodityTeam(id);
        }
        else{
            commodityTeam=new CommodityTeam();
        }
        return SUCCESS;
    }
    public String save()throws Exception{
        if(cancel!=null){
           return CANCEL;
        }
        if(delete!=null){
            return delete();
        }
        boolean isNew=(commodityTeam.getId()==null);
        commodityTeam=commodityTeamManager.saveCommodityTeam(commodityTeam);
        String key=(isNew)?"commodityTeam.added":"commodityTeam.updated";
        saveMessage(getText(key));
        if(!isNew){
            return INPUT;
        }
        else {
            return SUCCESS;
        }
    }

}
